<template>
  <div>
    <el-form :inline="true"  >
  <el-form-item label="链接">
    <el-input v-model="url" placeholder="链接"></el-input>
  </el-form-item>
  
  <el-form-item>
    <el-button type="primary" @click="onSubmit">查询</el-button>
  </el-form-item>
</el-form>
    <el-table
      :data="list"
      border
      style="width: 100%">
      <el-table-column
        label="用户信息"
        >
         <template #default="scope" >
           <div v-if="users[scope.row.token]">
            <el-image
      style="max-width: 50px; max-height: 50px"
      :src="users[scope.row.token]['avatar']"
      :fit="fit"></el-image>
      <div>{{users[scope.row.token]['nickname']}}</div>
      <div>豆子：{{users[scope.row.token]['score']}}</div>
      </div>
         </template>
      </el-table-column>
      <el-table-column
        prop="url"
        label="链接"
        >
      </el-table-column>
      <el-table-column
       
        label="请求耗时"
        >
        <template #default="scope" >
           <div >
            {{Number( scope.row.dt/1000000 ).toFixed(2)}}毫秒
          </div>
          </template>
      </el-table-column>
      <el-table-column
        label="访问时间">
      
       <template #default="scope" >
           <div >
            {{$g.time2date(scope.row.time,'yyyy-m-d h:i:s')}}
          </div>
          </template>
          </el-table-column>
      <el-table-column
        prop="code"
        label="状态码">
      </el-table-column>
    </el-table>
    <el-pagination
    background
   
    @current-change="handleCurrentChange"
 
    :page-size="pagesize"
    :total="total">
  </el-pagination>
  </div>
</template>

<script>
import post from "@/post"

export default {
  data(){
    return {
      list :[],
      total:0,
      page : 1,
      url:'',
      pagesize:10,
      users: {}
    }
  },
  mounted(){
    this.getList()
    
  },

  methods:{
    getList(){
      post("/request",{page:this.page,url:this.url}).then(d=>{
        this.total = d.total
        this.pagesize = d.pagesize
        this.pageall = d.pageall
        this.now = d.now
        this.list = d.list
        var users = {}
        d.users.forEach(v => {
          users[v['token']] = v
        })
        this.users = users
      })
    },
   handleCurrentChange(d){
     this.page = d
     this.getList()
   },
   onSubmit(){
     this.page = 1
     this.getList()

   }
  }
}
</script>

<style scoped>

</style>

